<template>
    <div>
        <h2>公告信息显示</h2>
        <input type="button" value="新增" class="btn btn-info" @click="add">
        <input type="button" value="导出" class="btn btn-primary" @click="Dao">

        <div>
            标题：
            <input type="text" v-model="cc.title">
            公告类型：
            <select v-model="cc.typeName">
                <option value="">请选择</option>
                <option :value="item.Name" v-for="item in data.list" :key="item.Id">{{ item.Name }}</option>
            </select>
            <input type="button" value="查询" class="btn btn-info" @click="getshow">
        </div>

        <table class="table table-bordered">
            <tbody>
                <tr class="bg-primary">
                    <td>Id</td>
                    <td>标题</td>
                    <td>分类</td>
                    <td>图片</td>
                    <td>状态</td>
                    <td>发布时间</td>
                    <td>发布人</td>
                    <td>公告类型</td>
                    <td>操作</td>
                </tr>

                <tr v-for="item in aa.list" :key="item.Id">
                    <td>{{ item.Id }}</td>
                    <td>{{ item.Title }}</td>
                    <td>{{ item.FenLei == 1 ? "服务协议" : "" }}</td>
                    <td>
                        <img :src="item.Photo" height="100" width="100" alt="">
                    </td>
                    <td>{{ item.State == 0 ? "显示" : "隐藏" }}</td>
                    <td>{{ moment(item.FaTime).format('YYYY-MM-DD HH:mm:ss') }}</td>
                    <td>{{ item.FaName == 1 ? "admin" : "" }}</td>
                    <td>{{ item.TypeName }}</td>
                    <td>操作</td>
                </tr>
            </tbody>
        </table>

    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import axios from 'axios';
import { useRouter, useRoute } from 'vue-router'
const router = useRouter();
const route = useRoute();
import moment from 'moment';
//----导出---
const Dao=()=>{
    location.href='https://localhost:7074/api/Info/ExportExcel';
}

//-----下拉绑定-----
onMounted(() => {
    getBang();
    getshow();
})
let data: any = reactive({
    list: []
})
const getBang = () => {
    axios({
        method: 'get',
        url: '/api/Info/ShowType'
    })
        .then(res => {
            console.log(res);
            data.list = res.data;
        })
        .catch(err => {
            console.log(err);
        })
}
//---显示---
let aa: any = reactive({
    list: []
})
let cc: any = reactive({
    title: "",
    typeName: "",
})
const getshow = () => {
    axios({
        method: 'get',
        url: '/api/Info/ShowInfo',
        params: cc
    })
        .then(res => {
            console.log(res);
            aa.list = res.data;
        })
        .catch(err => {
            console.log(err);
        })
}


const add = () => {
    router.push('/infoAdd');
}
</script>

<style scoped></style>